Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: multiple values ​​in one variable

  1. #1

    Default multiple values ​​in one variable

    hi

    how can i store level.a1, level.a2 , level.a3, level.a4 and level.a5 in the variable level.vr1

    pseudocode : level.vr1 = level.a1 + level.a2 + level.a3 + level.a4 + level.a5

    Boni

  2. #2
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Hi

    You could store the values in an array

    So you would turn level.vr1 from a variable into an array

    level.vr1[1] = level.a1
    level.vr1[2] = level.a2
    level.vr1[3] = level.a3

    See http://gronnevik.se/rjukan/index.php...Language#toc10

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  3. #3

    Default

    hey purple

    Thanks for the reply

    What i'm trying to achieve is to use level.vr1 for all the entities in the list like

    level.vr1[1] = level.a1
    level.vr1[2] = level.a2
    level.vr1[3] = level.a3
    level.vr1[4] = level.a4
    level.vr1[5] = level.a5
    level.vr1[6] = level.a6

    if( self cansee level.vr1 ? ) <- what to write here to make self react if it sees level.a1 or level.a2 or level.a3 ...

    By the way, what's with the ingame browser in MoHAA,
    i thought it would stop working on May 31,
    but it's still working fine !

  4. #4
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    You would still save all the entities into the array and just loop through each iteration in a for() loop and then add the cansee check

    Code:
    for (local.i = 1; local.i <= level.vr1.size; local.i++)
        {    
             if(self cansee level.vr1[local.i])
             {
             //do code
             }
    
        }
    It will loop through each entity saved in the array until it reaches the end.

    GameSpy Shutdown got postponed till end of this month so June 30th
    See
    http://www.x-null.net/forums/showthr...ssue-IMPORTANT
    and
    www.ea.com/1/service-updates

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  5. #5
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,567

    Default

    yeah about for , all i read is it loops like while , but complix or something like dat , any good demonstration

  6. #6
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Try Reading up on it on the link i posted on first reply


    The for statement

    The for statement is very similar to the while statement, but its declaration is more complex; making it easier to adapt to special cases:

    Code:
    for ( statement1 ; expr ; statement2 )
     {
       statement
       ...
       statement
     }
    At the start of execution of this entire statement, statement1 is executed. At the start of a cycle of the loop the expression expr is evaluated, and while the expression evaluates to true ( 1 ) the statement(s) within the "curly brackets" following the for clause are executed. At the end of each cycle of the loop, statement2 is executed.


    So With my example for the level.vr1 array
    Code:
    for (local.i = 1; local.i <= level.vr1.size; local.i++)
        {    
             if(self cansee level.vr1[local.i])
             {
             //do code
             }
    
        }
    It will first do the first statement which is local.i = 1,
    It will then check whether the expressing it true(1) , which is local.i <= level.vr1.size, so its if local.i is equal or less then the size of the array, which is true(1)
    If the expression is true , it executes what is inside the brackets, if false, it ends
    At the end of the loop , it will do the second statement which is local.i++, which is the same as local.i + 1
    It then starts the cycle again until the expression is false(0)

    Notice inside the brackets it uses local.i , which changes at each iteration because of the second statement, local.i++ , thus it will cycle through the variables inside the array without needing to re-write each one out.
    Last edited by Purple Elephant1au; June 17th, 2014 at 05:16 AM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  7. #7
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,567

    Default

    Thats nice , thx

    but is for always state 1 and expr and state 2 only ?

    no more ? no less ?

  8. #8

    Default

    OK, that worked like a charm
    Thanks for the code Purple
    hi RyBack, nice you joined this topic.

    And for the sake of completeness,
    here is the code

    Code:
    issniper:
    
    level.vr1[1] = level.a1
    level.vr1[2] = level.a2
    level.vr1[3] = level.a3
    level.vr1[4] = level.a4
    level.vr1[5] = level.a5
    level.vr1[6] = level.a6
    
    for (local.i = 1; local.i <= level.vr1.size; local.i++)
    {wait 2   
      if( self cansee level.vr1[local.i] && "springfield '03 sniper" == level.vr1[local.i].gun || "mauser kar 98d sniper" == level.vr1[local.i].gun )
      { $gp playsound gps4 } // sniper !
    }
    
    end

  9. #9
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    An interesting thing to note is that for loops are essentially just glorified while loops. They really just do this:
    Code:
    local.i = 1;
    while(local.i <= $player.size) 
    {
         $player[local.i] kill;
         local.i++;
    }
    Since iterating over arrays or collections of variables is such an integral part of programming, the for loop was born just for convenience's sake.
    Syntactic sugar as we programmers like to call it. Take the "local.i++", for instance. That's syntactic sugar for "local.i += 1" which in turn is
    syntactic sugar for "local.i = local.i + 1".
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  10. #10

    Default

    Quote Originally Posted by Boni View Post
    OK, that worked like a charm
    Thanks for the code Purple
    hi RyBack, nice you joined this topic.

    And for the sake of completeness,
    here is the code

    Code:
    issniper:
    
    level.vr1[1] = level.a1
    level.vr1[2] = level.a2
    level.vr1[3] = level.a3
    level.vr1[4] = level.a4
    level.vr1[5] = level.a5
    level.vr1[6] = level.a6
    
    for (local.i = 1; local.i <= level.vr1.size; local.i++)
    {wait 2   
      if( self cansee level.vr1[local.i] && "springfield '03 sniper" == level.vr1[local.i].gun || "mauser kar 98d sniper" == level.vr1[local.i].gun )
      { $gp playsound gps4 } // sniper !
    }
    
    end
    I suggest you add parenthesis between the OR logical operator like below.
    Because what you did in your code, it first checks if the player can see one of the vr, AND the vr has a springfield or SIMPLY the vr has a gun, this way is better :

    Code:
    if( self cansee level.vr1[local.i] && ( level.vr1[local.i].gun == "springfield '03 sniper" || level.vr1[local.i].gun == "mauser kar 98d sniper" ) )
    Logical operators in C/C++ share the same priority (left to right).

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •